from django.http import HttpResponse
from django.core import serializers
import json


def return_message(msg, code):
    json_str = {'msg': msg, 'code': code}
    return HttpResponse(json.dumps(json_str), content_type="application/text")


def return_json(data):
    return HttpResponse(json.dumps(data), content_type="application/json")


def return_page_info(obj_list, pagesize, total):
    d = {}
    d['rows'] = obj_list
    d['total'] = pagesize
    d['totalCount'] = total
    d['totalPage'] = (total / pagesize) if(total % pagesize == 0) else (total / pagesize + 1)
    return return_json(d)
